//
//  AlertWindow.m
//  居家馨
//
//  Created by 刘应平 on 16/11/24.
//  Copyright © 2016年 刘应平. All rights reserved.
//

#import "AlertWindow.h"

@implementation AlertWindow



/**  一般的弹窗提示  */
+ (void)normalAlertWithTitle:(NSString *)title message:(NSString *)message cancle:(AlertBlock)cancle sure:(AlertBlock)sure{
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
    
    /**  取消操作  */
    UIAlertAction *cancleHand = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        [[UIApplication sharedApplication].keyWindow.rootViewController dismissViewControllerAnimated:YES completion:nil];
    }];
    
    /**  确认操作  */
    UIAlertAction *sureHandle = [UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        if (sure) {
            sure();
        }
    }];
    
    [alertController addAction:cancleHand];
    [alertController addAction:sureHandle];
    
    
    [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:alertController animated:YES completion:nil];


}

/**  判断  */
+ (void)judgeWithTitle:(NSString *)title message:(NSString *)message{
    
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
    [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:alertController animated:YES completion:nil];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [[UIApplication sharedApplication].keyWindow.rootViewController dismissViewControllerAnimated:YES completion:nil];
    });
}


/**  照相和相册  */
+ (void)visteralbumAndTakePhoteWithTitle:(NSString *)title message:(NSString *)message visterAlbum:(AlertBlock)visterAlbum takePhoto:(AlertBlock)takePhoto cancle:(AlertBlock)cancle{
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleActionSheet];
    /**  访问相册  */
    UIAlertAction *visterAlbum1 = [UIAlertAction actionWithTitle:@"相册" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        if (visterAlbum) {
            visterAlbum();
        }

    }];
    /**  照相  */
    UIAlertAction *takePhoto1 = [UIAlertAction actionWithTitle:@"照相" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        if (takePhoto) {
            takePhoto();
        }
    }];
    
    [takePhoto1 setValue:[UIColor themeColor] forKey:@"_titleTextColor"];
    
    /**  取消操作  */
    UIAlertAction *cancleHand = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
       [[UIApplication sharedApplication].keyWindow.rootViewController dismissViewControllerAnimated:YES completion:nil];
    }];
    [cancleHand setValue:[UIColor redColor] forKey:@"_titleTextColor"];
    [alertController addAction:visterAlbum1];
    [alertController addAction:takePhoto1];
    [alertController addAction:cancleHand];
    
    [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:alertController animated:YES completion:nil];
    
    

}






@end
